package test.my;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class ReadFile {

	public static void main(String[] args) throws IOException{
		String resultString = "final/";
		String suffixString = ".dat";
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("data/wv.dat")));
		String data = null;
		int codenumber = 0;
		while((data = br.readLine()) != null){
			String filename = resultString + String.valueOf(codenumber) + suffixString;
			data = data.substring(data.indexOf(" ") + 1);
			PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename)), true);
			pw.println(data);
			pw.close();
			//BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename)));
			//bw.write(data);
			//bw.close();
			System.out.println(codenumber);
			++codenumber;
		}
		System.out.println("Finished!");
		br.close();
	}
}
